﻿using System;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;

namespace NetMicro.AutoMapper
{
    /// <summary>
    /// automapper
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 自动扫描注册继承profile的类
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddMapper(this IServiceCollection services)
        {
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            return services;
        }

        /// <summary>
        /// 自定义类注册
        /// </summary>
        /// <param name="services"></param>
        /// <param name="assemblies"></param>
        /// <returns></returns>
        public static IServiceCollection AddMapper(this IServiceCollection services, params Assembly[] assemblies)
        {
            services.AddAutoMapper(assemblies);
            return services;
        }

        /// <summary>
        /// 自定义注册
        /// </summary>
        /// <param name="services"></param>
        /// <param name="profileAssemblyMarkerTypes"></param>
        /// <returns></returns>
        public static IServiceCollection AddMapper(this IServiceCollection services, params Type[] profileAssemblyMarkerTypes)
        {
            services.AddAutoMapper(profileAssemblyMarkerTypes);
            return services;
        }
    }
}
